package com.utc.teamcenter.common.util;

import com.teamcenter.rac.kernel.TCPreferenceService;

public class DatasetTypeUtil {

	private static String preference = "DatasetType";

	private DatasetTypeUtil() {

	}

	public static boolean isSupportType(String type) {
		String[] mappings = TCUtil.getPreferenceService().getStringArray(
				TCPreferenceService.TC_preference_site, preference, null);
		if (mappings != null) {
			for (String mapping : mappings) {
				String[] value = mapping.split("::");
				if (value != null && value.length == 4 && value[0].equals(type)) {
					return true;
				}
			}
		}
		return false;
	}

	public static String getDatasetType(String type) {
		String[] mappings = TCUtil.getPreferenceService().getStringArray(
				TCPreferenceService.TC_preference_site, preference, null);
		if (mappings != null) {
			for (String mapping : mappings) {
				// doc::WordDoc::MSWord::word
				String[] value = mapping.split("::");
				if (value != null && value.length == 4 && value[0].equals(type)) {
					return value[2];
				}
			}
		}

		return null;
	}

	public static String getDatasetRef(String type) {
		String[] mappings = TCUtil.getPreferenceService().getStringArray(
				TCPreferenceService.TC_preference_site, preference, null);
		if (mappings != null) {
			for (String mapping : mappings) {
				// doc::WordDoc::MSWord::word
				String[] value = mapping.split("::");
				if (value != null && value.length == 4 && value[0].equals(type)) {
					return value[3];
				}
			}
		}

		return null;
	}
}
